package com.zmn.oms.zmn.business.impl.open;

import com.alibaba.fastjson.JSON;
import com.zmn.oms.business.interfaces.notifylog.OrderNotifyLogBService;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.model.entity.work.OrderWorkLogChange;
import com.zmn.oms.zmn.business.interfaces.open.OpenOrderBService;
import com.zmn.oms.zmn.business.interfaces.open.OrderChangeNotifyService;
import com.zmn.oms.zmn.business.interfaces.open.OrderNewNotifyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 类描述：订单状态变更通知
 *
 * @author liuying
 * @date 2019/06/13 20:36
 */
@Service("defaultNotifyService")
public class DefaultNotifyServiceImpl implements OrderChangeNotifyService, OrderNewNotifyService {
    private static final Logger logger = LoggerFactory.getLogger(DefaultNotifyServiceImpl.class);

    @Resource
    private OpenOrderBService openOrderBService;
    @Resource
    private OrderNotifyLogBService orderNotifyLogBService;

    @Override
    public void notifyChange(OrderWorkLogChange orderWorkLogChange) {
        try {
            ResultDTO resultDTO = openOrderBService.pushOrderInfo(orderWorkLogChange);
            orderNotifyLogBService.saveNotifyLog(resultDTO);
        } catch (OmsBaseException e) {
            logger.error(String.format("状态推送异常：%s，OrderWorkLogChange=[%s]",
                    e.getMessage(), JSON.toJSONString(orderWorkLogChange)), e);
        }
    }

    @Override
    public void notifyNewOrder(OrderWorkLogChange orderWorkLogChange) {
        try {
            ResultDTO resultDTO = openOrderBService.pushNewOrderInfo(orderWorkLogChange);
            orderNotifyLogBService.saveNotifyLog(resultDTO);
        } catch (OmsBaseException e) {
            logger.error(String.format("新单信息推送异常：%s，OrderWorkLogChange=[%s]",
                    e.getMessage(), JSON.toJSONString(orderWorkLogChange)), e);
        }
    }

}
